package nu.validator.htmlparser.dom;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

/**
 * @author <a href="mailto:tulkas.web@gmail.com">Tulkas</a>
 *
 */
public class DefaultTreeBuilder extends DOMTreeBuilder {
	private boolean docDeclared = false;

	private static DOMImplementation getDefaultDOMImpl() {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setNamespaceAware(true);
		DocumentBuilder builder;
		try {
			builder = factory.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			throw new RuntimeException(e);
		}
		return builder.getDOMImplementation();
	}

	public DefaultTreeBuilder() {
		super(getDefaultDOMImpl());
	}

	public boolean isDocDeclared() {
		return docDeclared;
	}

	public void setDocDeclared(boolean docDeclared) {
		this.docDeclared = docDeclared;
	}

	public Document getResultDoc() {
		return getDocument();
	}
}
